package james.timer;

import java.io.Serializable;
import java.util.Date;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class DefaultScheduledTask implements Job, ScheduledTask, Serializable {
	
	private long repeatInterval;
	
	String label;
	
	protected Date currentTime = new Date();
	
	protected int ctr = 0;

	@Override
	public void execute() {
		System.out.println("excuting real job" + this.getClass().getName());
		
		System.out.println("real label: " + label);
		
		System.out.println("ctr: " + ++ctr);
		
		Date newTime = new Date();
		System.out.println("real interval: " + (newTime.getTime() 
				- currentTime.getTime()));
		
		System.out.println();
		
		currentTime = newTime;
		

	}

	public String getLabel() {
		return label;
	}

	public void setLabel(String label) {
		this.label = label;
	}

	@Override
	public void setRepeatInterval(long interval) {
		repeatInterval = interval;

	}

	@Override
	public long getRepeatInterval() {
		return repeatInterval;
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	@Override
	public void execute(JobExecutionContext arg0) throws JobExecutionException {
		
        DefaultScheduledTask task = (DefaultScheduledTask) arg0.getJobDetail().getJobDataMap().get("label");
        task.execute();
        
		//System.out.println("label: " + label);
	}

}
